package com.bestcem.xm.om.controller.param;

import com.alibaba.fastjson.JSONObject;
import com.bestcem.xm.om.entity.OmRole;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * @author zq.ding <zq.ding@idiaoyan.com>
 * @version v1.0
 * @date 2021/12/24 17:25
 */
@NoArgsConstructor
@Data
@Slf4j
public class CreateOmRoleParam {

    @JsonProperty("permissions")
    private JSONObject permissions;
    @JsonProperty("title")
    private String title;

    public static OmRole convertToEntiy(CreateOmRoleParam createOmRoleParam) {
        if (Objects.isNull(createOmRoleParam)) {
            return null;
        }
        OmRole omRole = new OmRole();
        omRole.setTitle(createOmRoleParam.getTitle());
        omRole.setPermissions(createOmRoleParam.getPermissions().toJSONString());

        return omRole;

    }
}
